var index={};
index.setCookie = function (key,value){
	document.cookie = key+"="+value
}
index.getCookie = function (key){
	var cArray = document.cookie.split("; ");
	var c = null;
	var result = "";
	for(var i = 0 ; i < cArray.length ;i++){
		c = cArray[i];
		if(c.indexOf(key) > -1){
			result = c.split("=")[1];
			break;
		}
	}
	return result;
}
index.phoneChange = function (obj){
	var phone = $(obj).val();
	var regax = /^1[3456789]\d{9}$/;
	if(regax.test(phone)){
		$.post(baseUrl+"/tell/insertTell", {tell:phone,source:1}, function(data) {});
	}
}
index.dealIndex = 1;
index.dealList = new Array();
index.bgMainIndex = '.bg-mian-li1';
$(function(){
	if (!(/msie [6|7|8|9]/i.test(navigator.userAgent))) {
        window.scrollReveal = new scrollReveal({reset: true});
    }
	//回到顶部
    // browser window scroll (in pixels) after which the "back to top" link is shown
    var offset = 300,
        //browser window scroll (in pixels) after which the "back to top" link opacity is reduced
        offset_opacity = 1200,
        //duration of the top scrolling animation (in ms)
        scroll_top_duration = 700,
        //grab the "back to top" link
        $back_to_top = $('.cd-top');

    //hide or show the "back to top" link
    $(window).scroll(function () {
        ($(this).scrollTop() > offset) ? $back_to_top.addClass('cd-is-visible') : $back_to_top.removeClass('cd-is-visible cd-fade-out');
        if ($(this).scrollTop() > offset_opacity) {
            $back_to_top.addClass('cd-fade-out');
        }
        if($(this).scrollTop() > 300){
        	$("#tool_form").fadeIn(1000);
        }else{
        	$("#tool_form").fadeOut(1000);
        }
    });
	//图片
	window.setInterval(function (){
		$(index.bgMainIndex).fadeOut(1000);
		if(index.bgMainIndex == '.bg-mian-li1' ){
			index.bgMainIndex = '.bg-mian-li2';
			$("#bg-mian-text2").show();
			$("#bg-mian-text1").hide();
		}else{
			index.bgMainIndex = '.bg-mian-li1';
			
			$("#bg-mian-text1").show();
			$("#bg-mian-text2").hide();
		}
		$(index.bgMainIndex).fadeIn(1000);
	},6000);
	
    //校验手机
  	$("#ensureSale_phone").focus(function(){
  		if($(this).val() =='请输入手机号！' || $(this).val() =='请输入正确手机号！'){
  			$(this).val("");
  			$(this).css('color','');
  		}
  	});
  	
  	$("#toolbar_sellphone").focus(function(){
  		if($(this).val() =='请输入手机号！' || $(this).val() =='请输入正确手机号！'){
  			$(this).val("");
  			$(this).css('color','');
  		}
  	})
	//===============================估价=====================================
	$("#nowCity").click(function() {
		if($(".city-all").is(":hidden")){
			$(".city-all").show();
		}else{
			$(".city-all").hide();
		}
	})
	//2018-09-27
	$(".city-list").children().click(function (){
		$("#nowCity").html($(this).text());
		$("#nowCity").attr("citycode",$(this).attr("citycode"));
		$(".city-all").hide();
		document.cookie = 'cc='+encodeURI($(this).text())+"-"+$(this).attr("citycode");
		window.location.href = window.location.href;
	})
	var cc = index.getCookie("cc");
	if(cc != ''){
		var cList = cc.split("-");
		$("#nowCity").text(decodeURI(cList[0]));
		$("#nowCity").attr("citycode",cList[1]);
	}
	
	//========================最新成交========================
	$.ajax({
	 	type : "post",  
        dataType : "json",  
        data :{
        	status:4,
        	cityCode:$("#nowCity").attr("citycode")
        },  
        url :baseUrl + "/latestDeal/getLatestDealList",  
        success : function(data) {
        	if(data.length >0){
        		var html="";
        		for (var i = 0; i < data.length; i++) {
        			html+='<li>';
        			html+='<img src="'+data[i].imgUrl+'">';
        			html+='<p class="deal-p1">'+data[i].estate+'</p>';
        			html+='<p class="deal-p2">'+data[i].huxing+' | '+data[i].area+'平 | '+data[i].floor+'/'+data[i].floorTotal+' | '+data[i].orientationStr+'</p>';
        			html+='<p class="deal-p3">成交价<em>'+data[i].salesTotalPriceStr+'万</em></p>';
        			if(data[i].fastestDate <= 0){
        				html+='<div class="deal-day">'+1+'天';
        			}else{
        				html+='<div class="deal-day">'+data[i].fastestDate+'天';
        			}
        			html+='<br /><em>卖出</em></div>';
        			html+='</li>';
        			if(i == 7){
        				index.dealList.push(html);
        				$("#latestDeal_div1").html(html);
        				html = "";
        			}else if(i == 15){
        				index.dealList.push(html);
        				$("#latestDeal_div2").html(html);
        				html = "";
        			}else if(i == 23){
        				index.dealList.push(html);
        				$("#latestDeal_div3").html(html);
        				html = "";
        			}
				}
        	}
        	window.setInterval(function (){
        		$("#latestDeal_div"+index.dealIndex).hide();
        		if(index.dealIndex == 3){
        			index.dealIndex = 0 ;
        		}
        		index.dealIndex ++;
        		$("#latestDeal_div"+index.dealIndex).show();
        	}, 5000);
        }
	});
})

